package com.base.myproject.server;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.base.myproject.server.database.PoolMan;

public class Regiter {
	 public static boolean rigiter(String username ,String password,String email,String dept) {
	        
	        PoolMan pm = new PoolMan();
	        Connection con = null;

	        ResultSet rs1 = null;
	        try {
	            con = pm.getPool("test");
	            String sqlmore = "select count(*) num from regiter where bname ='"+username+"' or email='"+email+"'";
	             rs1 = pm.executeQuery(sqlmore);
	           rs1.next();
	           if(!rs1.getString("num").equals("0"))
               {
                   return false;
               }
	           String sqlmore2 = "select count(*) num from bcode where bname ='"+username+"' or email='"+email+"'";
	             rs1 = pm.executeQuery(sqlmore2);
	           rs1.next();
	           if(!rs1.getString("num").equals("0"))
             {
                 return false;
             }
	            String sql = "insert into regiter (bname,pass,email,dept) values('"+username+"','"+password+"','"+email+"','"+dept+"')";
	         if(  pm.Update(sql)>0)
	         {
	        
	            return true;
	         }
	        } catch (SQLException ex) {
	            ex.printStackTrace();
	        } catch (Exception ex) {
	            ex.printStackTrace();
	        }
	        finally
	        {
	        	pm.release();
	        }
	        
	        return false;
	    }
	    
}
